<?php

namespace Database\Seeders;

use App\Models\Actor;
use App\Models\Category;
use App\Models\Special;
use App\Models\Tag;
use App\Models\Video;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class VideoSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $actor_ids = Actor::query()->pluck('id');
        $special_ids = Special::query()->pluck('id');
        $category_ids = Category::query()->pluck('id');
        $tag_ids = Tag::query()->pluck('id');

        foreach (range(1, 50) as $value) {
            $video = Video::query()->create([
                'title' => '二次元动漫漂亮小姐姐跳舞视频 '.$value,
                'description' => fake()->text,
                'picture' => DownloadImage::putImage(),
                'vip' => fake()->boolean,
                'visits' => fake()->numberBetween(int2: 1000),
                'playback' => fake()->numberBetween(int2: 1000),
                'like' => fake()->numberBetween(int2: 1000),
                'score' => fake()->numberBetween(int2: 5),
                'videos' => [
                    [
                        'type' => 'video-item',
                        'fields' => [
                            'id' => Str::random(),
                            'path' => DownloadImage::putImage(),
                            'version' => '高清版',
                        ],
                    ],
                    [
                        'type' => 'video-item',
                        'fields' => [
                            'id' => Str::random(),
                            'path' => DownloadImage::putImage(),
                            'version' => '普通版',
                        ],
                    ],
                ],
            ]);

            $video->actors()->sync(
                $actor_ids->random(fn () => fake()->numberBetween(0, 3))
            );

            $video->specials()->sync(
                $special_ids->random(fn () => fake()->numberBetween(0, 3))
            );

            $video->categories()->sync(
                $category_ids->random(fn () => fake()->numberBetween(0, 3))
            );

            $video->tags()->sync(
                $tag_ids->random(fn () => fake()->numberBetween(0, 3))
            );
        }
    }
}
